﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace SiruEngine.Graphics
{
	public class AxisPrimitive : GeometricPrimitive
	{
		public AxisPrimitive(GraphicsDevice graphicsDevice)
			: this(graphicsDevice, 3)
		{
		}

		public AxisPrimitive(GraphicsDevice graphicsDevice, float total_size)
		{
			Vector3 normal = new Vector3(0, 1, 0);
			Vector3 normal_x = new Vector3(1, 0, 0);

			AddVertex(new Vector3(total_size, 0, 0), normal);
			AddVertex(new Vector3(-total_size, 0, 0), normal);
            AddVertex(new Vector3(0, total_size, 0), normal_x);
            AddVertex(new Vector3(0, -total_size, 0), normal_x);
            AddVertex(new Vector3(0, 0, total_size), normal);
			AddVertex(new Vector3(0, 0, -total_size), normal);

			AddIndex(0);
			AddIndex(1);
			AddIndex(2);
			AddIndex(3);
			AddIndex(4);
            AddIndex(5);

			InitializePrimitive(graphicsDevice);

			// line으로 변경
			ChangePrimitiveType(PrimitiveType.LineList);
		}

		public override bool Picking(Matrix world, Matrix view, Matrix projection, Vector2 pt_cursor)
		{
			Vector4 pt = new Vector4(0, 1, 0, 0);
			pt = Vector4.Transform(Vector4.Transform(Vector4.Transform(pt, world), view), projection);
			pt /= pt.W;
			pt.X /= pt.Z;
			pt.Y /= pt.Z;
			pt.Z /= pt.Z;
			return false;
		}
	}
}
